home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
autocomplete_manager-2.3-fx.xpi
/
chrome
/
acmanager.jar
/
content
/
treeUtils.js
< prev
Wrap
Text File
|
2008-03-14
|
3KB
|
112 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): Nikitas Liogkas <nikitas@acm.org>
* Version: 2.3
*
* ***** END LICENSE BLOCK ***** */
// treeUtils.js
// History Manager tree utility functions; code taken from cookieviewer/treeUtils.js
// returns the current selections on the tree
function acm_getTreeSelections(tree)
{
var selections = [];
var select = tree.view.selection;
if (select) {
// different selection blocks
var count = select.getRangeCount();
var min = new Object();
var max = new Object();
for (var i = 0; i < count; i++) {
select.getRangeAt(i, min, max);
for (var k = min.value; k <= max.value; k++) {
if (k !== -1)
selections[selections.length] = k;
}
}
}
return selections;
}
// sorts the tree and remembers the most recent selection
function acm_sortHistoryTree()
{
// remember which item was selected so we can restore it after the sort
var selections = acm_getTreeSelections(acm_treeHistory);
var selectedId = selections.length ? acm_history[selections[0]].id : -1;
// do the sorting
acm_history.sort(acm_alphaHistorySortFun);
// restore the original selection: scan the array for the unique id of the previously selected entry
var selectedRow = -1;
if (selectedId >= 0) {
for (var i = 0, len = acm_history.length; i < len; i++) {
if (acm_history[i].id === selectedId) {
acm_treeHistory.view.selection.select(i);
selectedRow = i;
break;
}
}
}
// display the results
acm_treeHistory.treeBoxObject.invalidate();
if (selectedRow >= 0)
acm_treeHistory.treeBoxObject.ensureRowIsVisible(selectedRow);
}
// sorts in alphabetical order, after ignoring common protocols and prefixes
function acm_alphaHistorySortFun(candidateA, candidateB)
{
// are we in the Add Entry dialog?
if (document.getElementById("acm_addEntryBox")) {
acm_histSortCriterion = opener.acm_histSortCriterion;
acm_histSortDirection = opener.acm_histSortDirection;
}
// leave as is for URLs, munge for titles
var candA, candB;
if (acm_histSortCriterion === "URL") {
candA = candidateA;
candB = candidateB;
}
else {
// manufacture appropriate objects to pass as arguments
candA = new Object();
candA.strippedURL = candidateA.strippedTitle;
candA.URL = "";
candB = new Object();
candB.strippedURL = candidateB.strippedTitle;
candB.URL = "";
}
// NOTE: acm_checkBookFirst is false here
var retvalue = acm_alphaURLCompareFun(candA, candB);
// ascending or descending?
if (acm_histSortDirection)
return retvalue;
else
return -retvalue;
}